package com.study.spmongodb.book.wwj.char02;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author study
 * @version 1.0
 * @date 2020/11/24 14:11
 */
public class ThreadCounter extends Thread {

    final static AtomicInteger counter = new AtomicInteger(0);

    public static void main(String[] args) {
        try {
            while (true){
                new ThreadCounter().start();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void run() {
        System.out.println("the "+ counter.getAndIncrement()+" thread be created.");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
